<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/24/024
 * Time: 20:12
 */

namespace app\admin\validate;

class SubmitParamValidate extends \think\Validate
{

    const SCENE_ADD = 'add'; //添加参数
    const SCENE_EDIT = 'edit'; //编辑参数
    const SCENE_REMOVE = 'remove'; //删除参数


    protected $rule = [
        'id' => 'require|number',
        'sid' => 'require|number',
        'type' => 'require|number',
        'title'  =>  'require|max:32',
        'skey'  =>  'require|max:32',
    ];


    protected $message  = [
        'sid.require' => '任务ID必须',
        'sid.number' => '任务ID必须为数字',
        'type.require' => '类型必须',
        'type.number' => '必须为数字',
        'title.require' => '标题必须',
        'title.max' => '标题最大长度32',
        'skey.require' => '关键字必须',
        'skey.max' => '关键字最大长度32',
    ];
    
    //场景
    protected $scene  = [
       self::SCENE_ADD => ['type', 'title', 'sid', 'skey'],
       self::SCENE_EDIT => ['id', 'type', 'title', 'sid', 'skey'],
       self::SCENE_REMOVE => ['id'],
    ];

    
    // 参数账号，以字母开头，长度在4-30之间，只能包含字母、数字和下划线。
    public function isKey($value) {
        $reg = "/[0-9a-zA-Z_]{4,30}$/";
        return preg_match($reg, $value) ? true : '参数关键字，长度在4-30之间，只能包含字母、数字和下划线';
    }

}